trivial-httpd: add option to specify the port
authorGiuseppe Scrivano <gscrivan@redhat.com>
Thu, 7 May 2015 09:13:43 +0000 (11:13 +0200)
committerGiuseppe Scrivano <gscrivan@redhat.com>
Thu, 7 May 2015 14:16:27 +0000 (16:16 +0200)
I use the trivial httpd server locally. Each time I restart the
server, I end up modifying manually the config file for other repos so
to point to the correct port. In this way I can just re-use the same
port.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
doc/ostree-trivial-httpd.xml
src/ostree/ot-builtin-trivial-httpd.c
tests/test-commit-sign.sh

index 1c2427272acb9eef4fc03b47c97b35ffe3909c51..2b846858481c881e102835c2945b54c84c3d05c1 100644 (file)
@@ -90,6 +90,14 @@ Boston, MA 02111-1307, USA.
                 </para></listitem>
             </varlistentry>
 
+            <varlistentry>
+                <term><option>--port</option>,<option>-P</option></term>
+
+                <listitem><para>
+                    Use the specified TCP port to listen on.
+                </para></listitem>
+            </varlistentry>
+
             <varlistentry>
                 <term><option>--force-range-requests</option></term>
 
index 11717148e16b922d8c1191f85d3f4765f475cd4b..d7701893543a6aa9f8fcd0f43e88b67da9f25bcd 100644 (file)
@@ -35,6 +35,7 @@ static char *opt_port_file = NULL;
 static gboolean opt_daemonize;
 static gboolean opt_autoexit;
 static gboolean opt_force_ranges;
+static gint opt_port = 0;
 
 typedef struct {
   GFile *root;
@@ -44,6 +45,7 @@ typedef struct {
 static GOptionEntry options[] = {
   { "daemonize", 'd', 0, G_OPTION_ARG_NONE, &opt_daemonize, "Fork into background when ready", NULL },
   { "autoexit", 0, 0, G_OPTION_ARG_NONE, &opt_autoexit, "Automatically exit when directory is deleted", NULL },
+  { "port", 'P', 0, G_OPTION_ARG_INT, &opt_port, "Use the specified TCP port", NULL },
   { "port-file", 'p', 0, G_OPTION_ARG_FILENAME, &opt_port_file, "Write port number to PATH (- for standard output)", "PATH" },
   { "force-range-requests", 0, 0, G_OPTION_ARG_NONE, &opt_force_ranges, "Force range requests by only serving half of files", NULL },
   { NULL }
@@ -349,10 +351,10 @@ ostree_builtin_trivial_httpd (int argc, char **argv, GCancellable *cancellable,
 
 #if SOUP_CHECK_VERSION(2, 48, 0)
   server = soup_server_new (SOUP_SERVER_SERVER_HEADER, "ostree-httpd ", NULL);
-  if (!soup_server_listen_all (server, 0, 0, error))
+  if (!soup_server_listen_all (server, opt_port, 0, error))
     goto out;
 #else
-  server = soup_server_new (SOUP_SERVER_PORT, 0,
+  server = soup_server_new (SOUP_SERVER_PORT, opt_port,
                             SOUP_SERVER_SERVER_HEADER, "ostree-httpd ",
                             NULL);
 #endif
index 4d13e1c9a3a5eab8a54469cd6f1f47a737dd8f45..8d673a93cb5b231a264af4766fd225c481088d9e 100755 (executable)
@@ -56,8 +56,9 @@ cd ${test_tmpdir}
 mkdir ${test_tmpdir}/httpd
 cd httpd
 ln -s ${test_tmpdir}/ostree-srv ostree
-${CMD_PREFIX} ostree trivial-httpd --autoexit --daemonize -p ${test_tmpdir}/httpd-port
+${CMD_PREFIX} ostree trivial-httpd --autoexit --daemonize -P 18081 -p ${test_tmpdir}/httpd-port
 port=$(cat ${test_tmpdir}/httpd-port)
+assert_streq $port 18081
 echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
 cd ${oldpwd}